package cn.edu.xmu.orderpayment.payment.model.vo;

import cn.edu.xmu.oomall.core.model.VoObject;
import cn.edu.xmu.orderpayment.payment.model.po.PaymentPo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author  Guanlin Wang
 * @date  2021-11-12
 */

@Data
@NoArgsConstructor
public class SimplePayment implements VoObject {
    @ApiModelProperty(value = "支付id")
    private long id;

    @ApiModelProperty(value = "交易流水号")
    private String tradeSn;

    @ApiModelProperty(value = "支付渠道id")
    private Long patternId;

    @ApiModelProperty(value = "支付金额")
    private Long amount;

    @ApiModelProperty(value = "单据id")
    private String documentId;

    @ApiModelProperty(value = "单据类型")
    private Byte documentType;//0 订单，1 保证金，2 订单订金， 3 订单尾款

    @ApiModelProperty(value = "开始支付时间")
    private LocalDateTime beginTime;

    @ApiModelProperty(value = "支付截止时间")
    private LocalDateTime endTime;

    @ApiModelProperty(value = "备注")
    private String descr;

    @ApiModelProperty(value = "实际支付金额")
    private long actualAmount;

    @ApiModelProperty(value = "实际支付时间")
    private LocalDateTime payTime;

    @ApiModelProperty(value = "支付状态")
    private Byte state;

    public SimpleAdminUser creator;//
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public LocalDateTime gmtCreate;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public LocalDateTime gmtModified;
    public SimpleAdminUser modifier;//adjust


    public PaymentPo createPo(){
        PaymentPo simplePaymentPo = new PaymentPo();
        simplePaymentPo.setPatternId(patternId);
        simplePaymentPo.setAmount(amount);
        simplePaymentPo.setDocumentId(documentId);
        simplePaymentPo.setDocumentType(documentType);
        simplePaymentPo.setBeginTime(beginTime);
        simplePaymentPo.setEndTime(endTime);
        simplePaymentPo.setDescr(descr);
        simplePaymentPo.setPayTime(payTime);
        simplePaymentPo.setTradeSn(tradeSn);
        simplePaymentPo.setActualAmount(actualAmount);
        simplePaymentPo.setState(state);
        return simplePaymentPo;
    }

    public SimplePayment(PaymentPo paymentPo){
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        id = paymentPo.getId();
        tradeSn = paymentPo.getTradeSn();
        patternId = paymentPo.getPatternId();
        amount = paymentPo.getAmount();
        documentId = String.valueOf( paymentPo.getDocumentId());
        documentType = paymentPo.getDocumentType();
        beginTime = paymentPo.getBeginTime();
        endTime = paymentPo.getEndTime();
        descr = paymentPo.getDescr();
        actualAmount = paymentPo.getActualAmount();
        payTime = paymentPo.getPayTime();
        state = paymentPo.getState();
        creator = new SimpleAdminUser(paymentPo.getCreatorId(), paymentPo.getCreatorName());
        gmtCreate = paymentPo.getGmtCreate();
        gmtModified = paymentPo.getGmtModified();
        modifier = new SimpleAdminUser(paymentPo.getModifierId(), paymentPo.getModifierName());
    }

    @Override
    public Object createVo() {
        return this;
    }

    @Override
    public Object createSimpleVo() { return this; }
}
